asmlinkage int sys_my_copy_call(const char *src_file, const char *dst_file)
{
    const int BUFSIZE = 1024;
    int f_read, f_write, read_num, write_num;
    char buf[BUFSIZE], *ptr;

    mm_segment_t old_fs; //段操作初始化
    old_fs = get_fs();   //保存原来的段
    set_fs(KERNEL_DS);   //设置为数据段

    if ((f_read = sys_open(src_file, O_RDONLY, S_IRUSR)) == -1) //打开源文件
        return -1;
    if ((f_write = sys_open(dst_file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1) //创建并打开目标文件
        return -2;
    while (read_num = sys_read(f_read, buf, BUFSIZE))
    {
        if (read_num == -1) //读错误
            return -3;
        else if (read_num > 0)
        {
            ptr = buf;
            while (write_num = sys_write(f_write, buf, read_num))
            {
                if (write_num == -1) //写错误
                    break;
                else if (read_num == write_num) //写完了所有字节
                    break;
                else if (write_num > 0) //写了部分字节，继续写
                {
                    ptr += write_num;
                    read_num -= write_num;
                }
            }
            if (write_num == -1) //写错误
                break;
        }
    }
    sys_close(f_read);
    sys_close(f_write);
    set_fs(old_fs); //恢复原来的段
    return 0;
}

asmlinkage long sys_mycopy(const char *src_file, const char *copy_file)
{
    int infd, outfd, count;
    char buf[256];
    mm_segment_t fs;
    fs = get_fs();
    set_fs(get_ds());
    if ((infd = sys_open(src_file, O_RDONLY, 0)) == -1)
    {
        return 1;
    }
    if ((outfd = sys_open(copy_file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
    {
        return 2;
    }
    while ((count = sys_read(infd, buf, 256)) > 0)
    {
        if (sys_write(outfd, buf, count) != count)
            return 3;
    }
    if (count == -1)
        return 4;
    sys_close(infd);
    sys_close(outfd);
    set_fs(fs);
    return 0;
}